using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Xms.Abp.AspNetCore.Mvc;

namespace IdentityManagement
{
    [RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
    [Area(IdentityRemoteServiceConsts.ModuleName)]
    [ControllerName("User")]
    [Route("api/management/identity/users")]
    public class IdentityUserController : XmsCrudController<IIdentityUserAppService, IdentityUserResult, Guid, IdentityUserPagedParameter, IdentityUserCreateParameter, IdentityUserUpdateParameter>, IIdentityUserAppService
    {
        protected IIdentityUserAppService UserAppService { get; }

        public IdentityUserController(IIdentityUserAppService userAppService)
        {
            UserAppService = userAppService;
        }

        [HttpGet]
        [Route("{id}/roles")]
        public virtual Task<List<IdentityRoleResult>> GetRolesAsync(Guid id)
        {
            return UserAppService.GetRolesAsync(id);
        }

        [HttpGet]
        [Route("assignable-roles")]
        public Task<List<IdentityRoleResult>> GetAssignableRolesAsync()
        {
            return UserAppService.GetAssignableRolesAsync();
        }

        [HttpPut]
        [Route("{id}/roles")]
        public virtual Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesParameter input)
        {
            return UserAppService.UpdateRolesAsync(id, input);
        }

        [HttpGet]
        [Route("by-username/{userName}")]
        public virtual Task<IdentityUserResult> FindByUsernameAsync(string userName)
        {
            return UserAppService.FindByUsernameAsync(userName);
        }

        [HttpGet]
        [Route("by-email/{email}")]
        public virtual Task<IdentityUserResult> FindByEmailAsync(string email)
        {
            return UserAppService.FindByEmailAsync(email);
        }

        [HttpGet]
        [Route("by-phone/{phone}")]
        public virtual Task<IdentityUserResult> FindByPhoneNumberAsync(string phone)
        {
            return UserAppService.FindByPhoneNumberAsync(phone);
        }
    }
}
